//package com.xinnet.mms.activemq.service.impl;
//
//import java.sql.Timestamp;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
//import javax.jms.JMSException;
//import javax.jms.Message;
//import javax.jms.MessageListener;
//import javax.jms.TextMessage;
//
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.xinnet.mms.allot.service.CustomAllotService;
//import com.xinnet.mms.customerManage.service.CustomerManageService;
//import com.xinnet.mms.customercare.service.CustomerCareService;
//import com.xinnet.mms.dept.service.DeptService;
//import com.xinnet.mms.entity.Customer;
//import com.xinnet.mms.entity.CustomerCare;
//import com.xinnet.mms.entity.Dept;
//import com.xinnet.mms.utils.CustomerManage;
//import com.xinnet.order.entity.IOrderCustomerCare;
//import com.xinnet.order.interfaces.OrderFacade;
//import com.xinnet.user.agent.service.AgentAgentService;
//import com.xinnet.user.agent.service.AgentUserInfoService;
//import com.xinnet.user.entity.db.AgentUserBasicInfo;
//import com.xinnet.vhost.service.VhostServiceData;
///**
// * 
// * 
// * @author 王湛智[wangzhanzhi@xinnet.com]
// *
// * @version 1.0
// *
// * @since 2014年3月19日
// *
// */
//public class Consumer implements MessageListener {
//	
//	@Autowired
//	private CustomerCareService customerCareService;
//	@Autowired
//	private DeptService deptService;
//	
//	//订单中心
////	@Autowired(required=false)
////	private OrderFacade orderFacade;
////	@Autowired(required=false)
////	VhostServiceData vhostServiceData;
//
//	//会员中心
//	@Autowired(required=false)
//	private AgentUserInfoService dbagentUserInfoService;
//	
//	@Autowired(required=false)
//	private AgentAgentService dbagentAgentService;
//	
//	@Autowired
//	private CustomerManageService customerManageService;
//	
//	@Autowired
//	private CustomAllotService customAllotService;
//	
//	
//	
//	
//	/**
//	 * 消息接受 已自动注入接收消息 只需做出相应的消息操作即可
//	 */
//	@Override
//	public void onMessage(Message message) {
//		
//		TextMessage TextMessage=(TextMessage)message;
//		try {
//            if (null != message) {
//            	
//            	String msg = TextMessage.getText();
//            	
//           	 if("AGENT_USER_CENTER".equals(msg)){
//           		 
//           		 //从会员中心同步客户数据
//           		this.synCustomerFromAgentUserCenter();
//           		
//           	 }else if("ORDER_CENTER".equals(msg)){
//           		 
//           		 //从订单中心同步客户服务表数据
//           		this.synCustomerCareFromOrderCenter();
//           	 }
//           }
//		} catch (JMSException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
//	
//	
//	
//	/**
//	 * 从会员同步客户数据
//	 */
//	private void synCustomerFromAgentUserCenter() throws Exception{
//		Map<String,Object> agentUserMap = dbagentUserInfoService.getUserInfoByUpdateFlag();
//		int length = agentUserMap.size();
//		String[] agentCodeArray = new String[length];
//		List<Customer> needAddCustomerList = new ArrayList<Customer>();
//		List<Customer> needUpateCustomerList = new ArrayList<Customer>();
//		int i=0;
//		for (Iterator<String> iterator = agentUserMap.keySet().iterator(); iterator.hasNext();){
//			String  agentCode = (String) iterator.next();
//			AgentUserBasicInfo agentUserBasicInfo = (AgentUserBasicInfo)agentUserMap.get(agentCode);
//			if(agentUserBasicInfo==null){
//				continue;
//			}
//			String admUserCode = agentUserBasicInfo.getAdmUserCode();
//			String tempAgentCode = agentUserBasicInfo.getAgentCode();
//			String agentType = agentUserBasicInfo.getAgentType();
//			java.util.Date applyDate = agentUserBasicInfo.getApplyDate();
//			int id = agentUserBasicInfo.getId();
//			String organizeNameCn = agentUserBasicInfo.getOrganizeNameCn();
//			String password = agentUserBasicInfo.getPassword();
//			String payPassword = agentUserBasicInfo.getPayPassword();
//			String publicCityCn = agentUserBasicInfo.getPublicCityCn();
//			String publicCountryCn = agentUserBasicInfo.getPublicCountryCn();
//			
//			String publicProvinceCn = agentUserBasicInfo.getPublicProvinceCn();
//			String publicStreetCn = agentUserBasicInfo.getPublicStreetCn();
//			String publicZipCode = agentUserBasicInfo.getPublicZipCode();
//			String userCode = agentUserBasicInfo.getUserCode();
//			String userEmail = agentUserBasicInfo.getUserEmail();
//			String userFaxArea = agentUserBasicInfo.getUserFaxArea();
//			String userFaxInter = agentUserBasicInfo.getUserFaxInter();
//			String userFaxNumber = agentUserBasicInfo.getUserFaxNumber();
//			String userMobiInter = agentUserBasicInfo.getUserMobiInter();
//			String userMobiNumber = agentUserBasicInfo.getUserMobiNumber();
//			String userName = agentUserBasicInfo.getUserName();
//			String userNameCn = agentUserBasicInfo.getUserNameCn();
//			String userNameEmail = agentUserBasicInfo.getUserNameEmail();
//			String userPhoneArea = agentUserBasicInfo.getUserPhoneArea();
//			String userPhoneInter = agentUserBasicInfo.getUserPhoneInter();
//			String userPhoneNumber = agentUserBasicInfo.getUserPhoneNumber();
//			
//			String flag = agentUserBasicInfo.getUpdateFlag();
//			
//			Customer customer = new Customer();
//			customer.setCusId(id+"");
//			customer.setCname(userName);
//			customer.setPhone(userMobiNumber);
//			customer.setEmail(userEmail);
//			customer.setRegionalId(userPhoneArea);
//			customer.setIsAllot(0);
//			customer.setIsReceive(0);
//			customer.setIsReDevel(0);
//			customer.setIsBuy(0);
//			customer.setCustomerType(CustomerManage.NEW_CUSTOMER);
//			customer.setCustomerSource("网站");
//			java.util.Date now = new java.util.Date();
//			java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//			String dtStr = format.format(now);
//			customer.setAddTime(dtStr);
//			if("0".equals(flag)){
//				needAddCustomerList.add(customer);
//			}else if("1".equals(flag)){
//				needUpateCustomerList.add(customer);
//			}
//			agentCodeArray[i]=agentCode;
//			i++;
//		}
//		
//		if(needAddCustomerList.size()>0){
//			for (Iterator<Customer> iterator = needAddCustomerList.iterator(); iterator.hasNext();) {
//				Customer customer = (Customer) iterator.next();
//				customAllotService.allot(customer, CustomerManage.NEW_CUSTOMER);
//			}
//		}
//		if(needUpateCustomerList.size()>0){
//			for (Iterator<Customer> iterator = needUpateCustomerList.iterator(); iterator.hasNext();) {
//				Customer customer = (Customer) iterator.next();
//				customerManageService.updateCustomer(customer);
//			}
//		}
//		dbagentAgentService.updateUpdateFlag(agentCodeArray);
//
//	}
//	/**
//	 * 从订单中心同步客户服务表数据
//	 * @throws Exception
//	 */
//	private void synCustomerCareFromOrderCenter() throws Exception{
//   		//获取未同步的订单数据
////		List<CustomerCare> customerCareList = new ArrayList<CustomerCare>();
////   		List<String> orderCodeList = new ArrayList<String>();
////   		List<IOrderCustomerCare> orderCustomerCareList = orderFacade.queryCustomerCareOrder();
////   		if(orderCustomerCareList==null || orderCustomerCareList.size()==0){
////   			return;	
////   		}
////   		int length = orderCustomerCareList.size();
////   		String[] serviceIdArray = new String[length];
////   		for (int i = 0; i < orderCustomerCareList.size(); i++) {
////   			IOrderCustomerCare iOrderCustomerCare = orderCustomerCareList.get(i);
////   			String serviceId = iOrderCustomerCare.getServiceCode();
////   			serviceIdArray[i]=serviceId;
////   			//serviceIdArray[i]="V83539322427955";  test
////		}
////   		Map<String,Object>  dueTimeMap = vhostServiceData.getVhostByServiceCode(serviceIdArray);
////   		for (IOrderCustomerCare iOrderCustomerCare : orderCustomerCareList) {
////   			CustomerCare customerCare = new CustomerCare();
////   			//人员标识
////   			String empNo = iOrderCustomerCare.getUserCode();
////   			//customerCare.setEmpNo(empNo);
////   			//客户标识
////   			String cusId = iOrderCustomerCare.getAgentCode();
////   			customerCare.setCusId(cusId);
////   			//产品标识
////   			String productId = iOrderCustomerCare.getProductCode();
////   			customerCare.setProductId(productId);
////   			//人员名称
////   			String ename = iOrderCustomerCare.getUserName();
////   			//customerCare.setEname(ename);
////   			//是否付款
////   			String isPay=iOrderCustomerCare.getPaymentType();
////   			//人员所属组织结构
////   			Dept dept = deptService.getDeptByEmpNo(empNo);
////   			if(dept!=null){
////   	  			String deptId = dept.getId();
////   	   			customerCare.setDeptId(deptId);
////   			}
////   			//人员所属组织结构名称
////   			if(dept!=null){
////   	  			String deptName = dept.getDname();
////   	   			customerCare.setDname(deptName);
////   			}
////       		//产品名称	
////   			String productName = iOrderCustomerCare.getProductName();
////   			customerCare.setProductName(productName);
////   			//商品名称
////   			String goodsName = iOrderCustomerCare.getGoodsName();
////   			customerCare.setGoodsName(goodsName);
////   			//商品价格
////   			double goodsPrice = iOrderCustomerCare.getPrice();
////   			customerCare.setGoodsPrice(goodsPrice);
////   			//订单编号	
////   			String orderId = iOrderCustomerCare.getOrderCode();
////   			customerCare.setOrderId(orderId);
////
////   			//服务编号
////   			String serviceId = iOrderCustomerCare.getServiceCode();
////   			customerCare.setServiceId(serviceId);
////   			//域名	 
////   			String domainName = iOrderCustomerCare.getDomainName();
////   			customerCare.setDomainName(domainName);
////   			//购买日期
////   		   Timestamp buyDateTimestamp = iOrderCustomerCare.getOperateTime();
////   		   SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////   		   java.util.Date utilBuyDate = dateFormat.parse(buyDateTimestamp.toString());
////   		   java.sql.Date sqlBuyDate = new java.sql.Date(utilBuyDate.getTime());
////   		   customerCare.setBuyDate(sqlBuyDate);
////   		   customerCare.setIsPay(isPay);
////   		   //到期时间? 根据serviceId 到product_service取
////   		   String dueTimeStr = (String)dueTimeMap.get(serviceId);
////   		   java.util.Date utilDueTime = dateFormat.parse(dueTimeStr);
////   		   java.sql.Date sqlUtilDueTime = new java.sql.Date(utilDueTime.getTime());
////   		   customerCare.setDueTime(sqlUtilDueTime);
////   		   
////   		   //到期预警时间?
////   			
////   		   //是否提示预警	 ?
////   			
////   			//提示处理中标识 ?
////   			
////   			//提成比例?
////   			
////   			//销售额?
////   			
////   			//提成?
////   			
////   			//开发方式?
////   			
////   			//推送人员标识?
////   			
////   			//推送人员名称?
////   			
////   			//推送所得金额?
////   			
////   			//返利金额
////   		   double rebateMoney = iOrderCustomerCare.getRebateMoney();
////   		   customerCare.setRebateMoney(rebateMoney);
////   			
////   			//退费	?
////   		   String refund = iOrderCustomerCare.getIsReturns();
////   		   customerCare.setRefund(Integer.parseInt(refund));
////
////   			//年限?
////   			
////   		   //添加List
////   			orderCodeList.add(orderId);
////   			customerCareList.add(customerCare);
////		}
////		//订单入库
////   		for (CustomerCare customerCare : customerCareList) {
////   			customerCareService.addOrders(customerCare);
////
////		}
////   		//根据订单编号，更新同步状态
////   		orderFacade.updateCustomerCareOrder(orderCodeList);
////   		System.out.println("ORDER_CENTER "+"添加数据  "+new java.util.Date()); 
//	}
//}
